home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / translate / sgml2flat.c < prev    next >
C/C++ Source or Header  |  1995-12-10  |  1KB  |  57 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <errno.h>
  5.  
  6. /*
  7.     sgml2txt produce nice ASCII text, but still produce
  8.     some features such as overstike and underline.
  9.  
  10.     Linuxconf's help support it. Some viewer do not.
  11.     This program read a sgml translated file and write
  12.     a file without those features
  13. */
  14.  
  15. static FILE *myfopen (const char *fname, const char *mode)
  16. {
  17.     FILE *ret = fopen (fname,mode);
  18.     if (ret == NULL){
  19.         fprintf (stderr,"Can't open file %s: %s\n"
  20.             ,fname,strerror(errno));
  21.         exit (-1);
  22.     }
  23.     return ret;
  24. }
  25. int main (int argc, char *argv[])
  26. {
  27.     int ret = -1;
  28.     if (argc != 3){
  29.         fprintf (stderr,
  30.             "sgml2flat sourcefile destinationfile\n"
  31.             "source and destination CAN'T be the same\n");
  32.     }else{
  33.         FILE *fin = myfopen (argv[1],"r");
  34.         FILE *fout = myfopen (argv[2],"w");
  35.         char buf[500];
  36.         while (fgets(buf,sizeof(buf)-1,fin)!=NULL){
  37.             char buf2[500];
  38.             char *pts = buf;
  39.             char *ptd = buf2;
  40.             while (*pts != '\0'){
  41.                 if (pts[1] == 8){
  42.                     pts += 2;
  43.                 }else if (pts[0] == 0xad){
  44.                     pts[0] = '-';
  45.                 }
  46.                 if (*pts == '\0') break;
  47.                 *ptd++ = *pts++;
  48.             }
  49.             *ptd = '\0';
  50.             fputs (buf2,fout);
  51.         }
  52.         fclose (fin);
  53.         ret = fclose (fout);
  54.     }
  55.     return ret;
  56. }
  57.